package sy.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import sy.model.TcustomerInfo;
import sy.pageModel.Json;
import sy.pageModel.PagecustomerInfo;
import sy.service.TcustomerInfoServiceI;

@Controller
@RequestMapping("/customerInfoController")
public class TcustomerInfoController {

	private TcustomerInfoServiceI customerInfoService;

	
	public TcustomerInfoServiceI getCustomerInfoService() {
		return customerInfoService;
	}

	@Autowired
	public void setCustomerInfoService(TcustomerInfoServiceI customerInfoService) {
		this.customerInfoService = customerInfoService;
	}

	@RequestMapping("/treegrid")
	@ResponseBody
	public List<PagecustomerInfo> treegrid() {
		return customerInfoService.treegrid();
	}

	/*@RequestMapping("/allTreeNode")
	@ResponseBody
	public List<Resource> allTreeNode() {
		return resourceService.allTreeNode();
	}*/

	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	public Json add(@ModelAttribute("customerInfo")PagecustomerInfo customerInfo) {
		Json j = new Json();
		j.setSuccess(true);
		j.setObj(customerInfoService.add(customerInfo));
		j.setMsg("添加成功!");
		return j;
	}

	@RequestMapping("/remove")
	@ResponseBody
	public Json remove(String ids) {
		System.out.println(ids+"ninai");
		Json j = new Json();
		customerInfoService.remove(ids);
		j.setSuccess(true);
		j.setObj(ids);
		j.setMsg("删除成功!");
		return j;
	}

	@RequestMapping("/edit")
	@ResponseBody
	public Json edit(PagecustomerInfo customerInfo) {
		System.out.println("333333");
		Json j = new Json();
		j.setSuccess(true);
		j.setObj(customerInfoService.edit(customerInfo));
		//System.out.println("okokok");
		//j.setMsg("编辑成功!");
		return j;
	}

}
